package homework.day03;


import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

/**
 * 使用PrintWriter完成记事本工具
 * 程序启动后要求将用户在控制台上输入的每一行字符串都写入到文件note.txt中
 * 如果用户在控制台单独输入了"exit"时，程序退出
 */
public class Test05 {
    public static void main(String[] args) throws FileNotFoundException {
        FileOutputStream fos = new FileOutputStream("note.txt",true);
        OutputStreamWriter osw= new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        BufferedWriter  bw = new BufferedWriter(osw);
        PrintWriter pw = new PrintWriter(bw,true);

        Scanner scanner = new Scanner(System.in);
        while(true){
            String line = scanner.nextLine();
            if("exit".equalsIgnoreCase(line)){
                break;
            }
            pw.println(line);
        }
        System.out.println("写出完毕！");
        pw.close();
    }

}
